function defineProperty(obj, key, value) {
    return key in obj ? Object.defineProperty(obj, key, {
        value: value,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : obj[key] = value, obj;
}

var utility, appInstance = getApp(), dataProvider = require("../../provider/dataApi.js"), util = (require("../../provider/pipe.js"), 
require("../../we7/resource/js/util.js"));

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        isSetShow: !1,
        show: !1,
        phoneNumber: "",
        isShow: new Date().getTime()>1731391816000,
        userInfo: (utility = {
            name: "",
            id_card: "",
            student_name: ""
        }, defineProperty(utility, "id_card", ""), defineProperty(utility, "school", ""), defineProperty(utility, "phone", ""), defineProperty(utility, "grade", ""), 
        defineProperty(utility, "sex", ""), utility),
        studentInfo: "",
        verificationCode: "",
        isCodeSent: !1,
        codeText: "获取验证码",
        newPhoneNumber: ""
    },
    onLoad: function(options) {
        wx.getStorageSync("uid") ? this.setData({
            statusBarHeight: getApp().globalData.statusBarHeight,
            titleBarHeight: getApp().globalData.titleBarHeight
        }) : wx.navigateTo({
            url: "/pages/login/login"
        });
    },
    editHeadimgBtn: function() {
        var that = this, uploadUrl = util.url("entry/wxapp/uploadImage", {
            m: "goouc_fullexam"
        });
        wx.showActionSheet({
            itemList: [ "拍照", "从手机相册选择" ],
            success: function(response) {
                "0" == response.tapIndex ? wx.chooseImage({
                    count: 1,
                    sizeType: [ "original", "compressed" ],
                    sourceType: [ "camera" ],
                    success: function(response) {
                        wx.showToast({
                            title: "正在上传...",
                            icon: "loading",
                            mask: !0,
                            duration: 1e4
                        }), wx.uploadFile({
                            url: uploadUrl,
                            filePath: response.tempFilePaths[0],
                            name: "upfile",
                            formData: {},
                            success: function(response) {
                                console.log(response);
                                var data = {};
                                that.setData((data["userInfo.headimg"] = response.data, data)), wx.hideToast();
                            },
                            fail: function(error) {
                                wx.hideToast(), console.log(error);
                            }
                        });
                    }
                }) : wx.chooseImage({
                    count: 1,
                    sizeType: [ "original", "compressed" ],
                    sourceType: [ "album" ],
                    success: function(response) {
                        console.log(response), wx.showToast({
                            title: "正在上传...",
                            icon: "loading",
                            mask: !0,
                            duration: 1e4
                        }), wx.uploadFile({
                            url: uploadUrl,
                            filePath: response.tempFilePaths[0],
                            name: "upfile",
                            formData: {},
                            success: function(response) {
                                console.log(response);
                                var headImageUrl = response.data;
                                dataProvider.updateHeadimg({
                                    uid: wx.getStorageSync("uid"),
                                    headimg: headImageUrl
                                }).then(function(response) {
                                    response = {}, that.setData((response["userInfo.headimg"] = headImageUrl, response)), wx.hideToast();
                                }).catch(function(error) {
                                    console.lgo(error);
                                });
                            },
                            fail: function(error) {
                                wx.hideToast(), console.log(error);
                            }
                        });
                    },
                    fail: function(error) {
                        console.log(error);
                    }
                });
            }
        });
    },
    inputblur: function() {
        this.getUserInfo(this.data.userInfo.name, this.data.userInfo.phone);
    },
    getUserInfo: function(name, phoneNumber) {
        var that = this;
        "" != name && null != name && "" != phoneNumber && null != phoneNumber && null != phoneNumber && dataProvider.userinfo({
            phone: phoneNumber,
            name: name,
            op: "checkStudent"
        }).then(function(response) {
            if (console.log(response), response = response.data.list, console.log(response), "" !== response.length) {
                var data = {};
                that.setData((data.isSetShow = !0, data.studentInfo = response, data["userInfo.student_name"] = response.student_name, 
                data["userInfo.school"] = response.school_name, data["userInfo.grade"] = response.banji_name, data["userInfo.sex"] = response.sex, 
                data));
            }
        }).catch(function(error) {
            console.log(error);
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    goBind: function() {
        this.setData({
            show: !0
        });
    },
    confirm: function(event) {
        var that = this;
        console.log(event.detail), console.log(that.data.userInfo.phone), null == that.data.newPhoneNumber || that.data.newPhoneNumber.length < 11 ? (console.log(11), 
        wx.showToast({
            icon: "none",
            title: "请输入正确的手机号"
        })) : dataProvider.userinfo({
            phone: that.data.newPhoneNumber,
            code: that.data.verificationCode,
            uid: wx.getStorageSync("uid"),
            op: "checkcode"
        }).then(function(response) {
            wx.showToast({
                icon: "none",
                title: "绑定成功"
            }), that.getUserInfo(that.data.userInfo.name, that.data.newPhoneNumber), that.setData({
                isCodeSent: !0,
                phoneNumber: that.data.newPhoneNumber
            });
        }).catch(function(error) {
            console.log(error), that.setData({
                isCodeSent: !0
            }), wx.showToast({
                icon: "none",
                title: error.message
            });
        });
    },
    onClose: function() {
        this.setData({
            close: !1
        });
    },
    onShow: function() {
        var userInfo = wx.getStorageSync("userinfo");
        userInfo && (this.setData({
            userInfo: userInfo
        }), null != userInfo.phone && "" != userInfo.phone && "null" != userInfo.phone && this.setData({
            phoneNumber: userInfo.phone
        })), 1 == userInfo.stu_have && this.setData({
            isSetShow: !0
        }), console.log(userInfo), this.getUserInfo(this.data.userInfo.name, this.data.userInfo.phone);
    },
    getName: function(event) {
        var data = {};
        this.setData((data["userInfo.name"] = event.detail.value, data));
    },
    getXh: function(event) {
        var data = {};
        this.setData((data["userInfo.student_name"] = event.detail.value, data));
    },
    getIdcard: function(event) {
        var data = {};
        this.setData((data["userInfo.id_card"] = event.detail.value, data));
    },
    getSchool: function(event) {
        var data = {};
        this.setData((data["userInfo.school"] = event.detail.value, data));
    },
    getClass: function(event) {
        var data = {};
        this.setData((data["userInfo.grade"] = event.detail.value, data));
    },
    getPhone: function(event) {
        this.setData({
            newPhoneNumber: event.detail.value
        });
    },
    getCode: function(event) {
        this.setData({
            verificationCode: event.detail.value
        });
    },
    sendCode: function() {
        var that = this;
        /^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.data.newPhoneNumber) ? "获取验证码" == this.data.codeText || "重新发送" == this.data.codeText ? dataProvider.userinfo({
            phone: this.data.newPhoneNumber,
            uid: wx.getStorageSync("uid"),
            op: "getcode"
        }).then(function(response) {
            that.setData({
                codeText: "60秒"
            });
            var seconds = 60, intervalId = setInterval(function() {
                seconds--, that.setData({
                    codeText: seconds + "秒"
                }), seconds <= 0 && (that.setData({
                    codeText: "重新发送"
                }), clearInterval(intervalId));
            }, 1e3);
        }).catch(function(error) {
            console.log(error), wx.showToast({
                icon: "none",
                title: error.message
            });
        }) : wx.showToast({
            icon: "none",
            title: "请不要重复发送~"
        }) : wx.showToast({
            icon: "none",
            title: "请输入正确的手机号~"
        });
    },
    goToSave: function() {
        this.goSave(!0);
    },
    goSave: function(isFromSaveButton) {
        var that = this, userInfo = this.data.userInfo;
        "null" == userInfo.name || null == userInfo.name || "" == userInfo.name ? wx.showToast({
            title: "请输入姓名",
            icon: "none"
        }) : ("null" == userInfo.phone && (userInfo.phone = ""), dataProvider.userinfo({
            uid: wx.getStorageSync("uid"),
            name: userInfo.name,
            phone: userInfo.phone
        }).then(function(response) {
            console.log(response), 1 == response.data && (wx.showToast({
                icon: "none",
                title: "保存成功"
            }), that.updateUserInfo(), isFromSaveButton ? (wx.showToast({
                icon: "none",
                title: "保存成功"
            }), setTimeout(function() {
                wx.navigateBack({
                    delta: -1
                });
            }, 1e3)) : wx.showToast({
                icon: "none",
                title: "绑定成功"
            }), console.log(appInstance.globalData.userinfo));
        }).catch(function(error) {
            that.updateUserInfo(), isFromSaveButton && wx.showToast({
                icon: "none",
                title: "并未有任何改动哦"
            });
        }));
    },
    updateUserInfo: function() {
        dataProvider.userinfo({
            uid: wx.getStorageSync("uid"),
            op: "getinfo"
        }).then(function(response) {
            console.log(response), appInstance.globalData.userinfo = response.data.info;
        }).catch(function(error) {});
    },
    onShareAppMessage: function() {}
});